package com.itheima.controller;

import com.itheima.R;
import com.itheima.dto.PmsProductAttributeParam;
import com.itheima.service.PmsProductAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chensen
 * @create 2022/10/13/10:25
 */
@RestController
@RequestMapping("productAttribute")
public class PmsProductAttributeController {
    @Autowired
    private PmsProductAttributeService pmsProductAttributeService;

    /**
     * 根据商品分类的id获取商品属性及属性分类
     * @param productCategoryId
     * @return
     */
    @GetMapping("attrInfo/{productCategoryId}")
    public R getInfo(@PathVariable Long productCategoryId){
        return pmsProductAttributeService.getInfo(productCategoryId);
    }

    /**
     * 添加商品属性信息
     * @param productAttributeParam
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody PmsProductAttributeParam productAttributeParam){
        return pmsProductAttributeService.create(productAttributeParam);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public R delete(@RequestParam("ids") List<Long> ids){
        return pmsProductAttributeService.delete(ids);
    }

    /**
     * 根据分类查询属性列表或参数列表
     * @param cid
     * @param type
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("list/{cid}")
    public R list(@PathVariable("cid") Long cid,
                             @RequestParam(value = "type") Integer type,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return pmsProductAttributeService.list(cid,type,pageNum,pageSize);
    }

    /**
     * 修改商品属性信息
     * @param id
     * @param productAttributeParam
     * @return
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Long id, @RequestBody PmsProductAttributeParam productAttributeParam){
        return pmsProductAttributeService.update(id,productAttributeParam);
    }

    /**
     * 查询单个属性
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R getItem(@PathVariable Long id){
        return pmsProductAttributeService.getItem(id);
    }

}
